import logging
from pathlib import Path
from logging.handlers import TimedRotatingFileHandler

# 创建日志目录
log_dir = Path(__file__).parent.parent.parent / "logs"
log_dir.mkdir(exist_ok=True)

# 配置日志处理器
handler = TimedRotatingFileHandler(
    filename=log_dir / "app.log",
    when='midnight',
    interval=1,
    backupCount=30,
    encoding='utf-8'
)

# 设置日志格式
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)

# 创建并配置logger
logger = logging.getLogger('app')
logger.setLevel(logging.INFO)
logger.addHandler(handler)

# 导出logger供其他模块使用
__all__ = ['logger'] 